#! /usr/bin/env python

"""Stock Analysis Tool used to analyze a list of stocks and adive on buy or no
buy"""

import argparse

def parse_args():
    """Define and parse args. Returns the output of parsing"""
    parser = argparse.ArgumentParser(description='Calculate RGV')
    parser.add_argument(
        'price', metavar='PRICE', type=float,
        help="Company's current price per share")
    parser.add_argument(
        'eps', metavar='EPS', type=float,
        help="Company's last 12 months Earnings Per Share (EPS)")
    parser.add_argument(
        'ltg', metavar='LTG', type=float,
        help="Company's long-term earnings growth estimate")
    parser.add_argument(
        '-y', '--yield', dest='aaa_yield', metavar='YIELD', type=float,
        default=8.5,
        help="The current yield on AAA corporate bonds (default: 8.5)")
    args = parser.parse_args()
    return args

def main():
    """This is where it begins!"""
    args = parse_args()

    # relative graham value
    value = args.eps * (8.5 + 2 * args.ltg) * 4.4 / args.aaa_yield
    print 'Price: {price}'.format(price=args.price)
    print 'Value: {value:0.2f}'.format(value=value)
    print '{dir}valued by {value:0.2f}%'.format(
        dir='YES: Under' if value > args.price else 'NO: Over',
        value=abs((value - args.price) / args.price * 100))

if __name__ == '__main__':
    main()
